#include "tim_app.h"

void Tim_set_duty(uint16_t duty)
{
    TIM3->CCR2 = (TIM3->ARR +1 )* (duty / 100.0f);
}

void Tim_set_freq(uint16_t freq)
{
    uint32_t Clock_freq = 1000000;

    uint32_t value = Clock_freq / freq - 1;

    TIM3->CCR2 = (value + 1) * (TIM3->CCR2 / TIM3->ARR);

    TIM3->ARR = value;

    TIM3->EGR = TIM_EGR_UG;
}
uint16_t freq = 1000;
uint16_t duty = 10;
uint16_t old_freq=1000;
uint16_t old_duty = 10;
void tim_proc(void)
{
    if(old_freq!= freq || old_duty!= duty)
    {
        Tim_set_freq(freq);
        Tim_set_duty(duty);
        old_freq = freq;
        old_duty = duty;
   }
}
